#include "App_485_Task.h"
#include "App_Lora_Task.h"
#include "App_Modbus_Proto.h"
#include "App_Send_Data_Task.h"
#include "App_Service_Task.h"
#include "board.h"
#include "log.h"
#include "system.h"

int main(void)
{
    // Target board initialization
    BoardInitMcu();

    SystemLoRaData.loraTxMutex = xSemaphoreCreateBinary();
    OsMutexRelease(SystemLoRaData.loraTxMutex);

#if defined(CONFIG_DTU_485)
    SystemLoRaData.rs485TxQueue = xQueueCreate(SYSTEM_DEVICE_NUM, sizeof(LoraDevice_t));
    if (SystemLoRaData.rs485TxQueue == NULL) {
        LOG_PRINTF(LL_DEBUG, "rs485TxQueue creat error.\r\n");
    }
#endif

    // xTaskCreate((TaskFunction_t)App_Service_Task, "Service", APP_Service_TASK_STACK_SIZE, NULL,
    // APP_Service_TASK_PRIORITY, NULL );
    xTaskCreate((TaskFunction_t)App_Lora_Task, "Lora", APP_LORA_TASK_STACK_SIZE, NULL, APP_LORA_TASK_PRIORITY, NULL);
#if defined(CONFIG_DTU_485)
    xTaskCreate((TaskFunction_t)App_485_Task, "485", APP_485_TASK_STACK_SIZE, NULL, APP_485_TASK_PRIORITY, NULL);
#endif
    xTaskCreate((TaskFunction_t)App_Send_Data_Check_Task, "Send", APP_SEND_DATA_TASK_STACK_SIZE, NULL,
                APP_SEND_DATA_TASK_PRIORITY, NULL);

    vTaskStartScheduler();
    LOG_PRINTF(LL_DEBUG, "exit.\r\n");
    for (;;) {}
}

#ifdef USE_FULL_ASSERT
void assert_failed(void* file, uint32_t line)
{
    (void)file;
    (void)line;

    while (1) {}
}
#endif